<?php

namespace common\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\MktSourceMember;

/**
 * MktSourceMemberSearch represents the model behind the search form about `common\models\MktSourceMember`.
 */
class MktSourceMemberSearch extends MktSourceMember
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'user_id', 'area_id', 'member_count', 'member_quanlity', 'member_age_min', 'member_age_max'], 'integer'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = MktSourceMember::find()->orderBy(['id' => SORT_DESC]);;

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'user_id' => $this->user_id,
            'area_id' => $this->area_id,
            'member_count' => $this->member_count,
            'member_quanlity' => $this->member_quanlity,
            'member_age_min' => $this->member_age_min,
            'member_age_max' => $this->member_age_max,
        ]);

        return $dataProvider;
    }


    public function searchWap($params, $query = null)
    {
        if ( null === $query) {
            $query = MktSourceMember::find()
                //->where(['status' => MktSourceMember::POST_STATUS_NORMAL])
                ->orderBy(['id' => SORT_DESC]);
        }

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
        	    'pagesize' => 20,
            ],            
            
        ]);
        
        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'user_id' => $this->user_id,
            'area_id' => $this->area_id,
            'member_count' => $this->member_count,
            'member_quanlity' => $this->member_quanlity,
            'member_age_min' => $this->member_age_min,
            'member_age_max' => $this->member_age_max,
        ]);

        return $dataProvider;
    }
    
}
